package apis

import (
	"fmt"
	"go-admin/app/alarm/models"
	"go-admin/app/alarm/service"
	"go-admin/app/alarm/service/dto"

	_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"

	"github.com/gin-gonic/gin"
	"github.com/go-admin-team/go-admin-core/sdk/api"
)

type SysAlarm struct {
	api.Api
}

// GetPage 获取报警列表
// @Summary 获取报警列表
// @Description 获取报警列表
// @Tags 报警
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} response.Response{data=response.Page{list=[]models.SysAlarm}} "{"code": 200, "data": [...]}"
// @Router /api/v1/sys-alarm [get]
// @Security Bearer
func (e SysAlarm) GetPage(c *gin.Context) {
	req := dto.SysAlarmGetPageReq{}
	s := service.SysAlarm{}
	err := e.MakeContext(c).
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	list := make([]models.SysAlarm, 0)
	var count int64

	err = s.GetPage(&req, &list, &count)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取SysAlarm失败，\r\n失败信息 %s", err.Error()))
		return
	}

	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}
